﻿using InnoWeb.CEND.BL.Service;
using InnoWeb.CEND.BL.Service.News;
using InnoWeb.CEND.BL.Service.Workshop;
using InnoWeb.CEND.Core.Model.Expert;
using InnoWeb.CEND.Core.Model.General;
using InnoWeb.CEND.Core.Model.News;
using InnoWeb.CEND.Core.Model.Workshop;
using InnoWeb.CEND.Data;
using InnoWeb.CEND.Data.Infrastructure;
using InnoWeb.CEND.UI.MVC.App_GlobalResources;
using InnoWeb.CEND.UI.MVC.Models;
//using InnoWeb.CEND.BL.Service.Page;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PagedList;
using InnoWeb.CEND.BL.Service.Reports;
using InnoWeb.CEND.BL.Service.Videos;
using InnoWeb.CEND.Core.Model.Reports;
using InnoWeb.CEND.Core.Model.Videos;

namespace InnoWeb.CEND.UI.MVC.Controllers
{
    public class HomeController : Controller
    {
        private const string connectionString = @"Server=N04155-1013\OMERSRV;Database=CendDB;Trusted_Connection=True;";

        private static WebSiteContext _context;
        private static IUnitOfWork _unitOfWork;

        private static GenericRepository<NewsItem> _newsItemRepository;
        private static GenericRepository<NewsContent> _newsContentRepository;
        private static NewsItemService _newsItemService;
        private static NewsContentService _newsContentService;

        private static GenericRepository<ExpertInfo> _expertInfoRepository;
        private static ExpertService _expertService;

        private static GenericRepository<SliderContent> _sliderRepository;
        private static SliderService _sliderService;


        private static GenericRepository<WorkshopItem> _workshopItemRepository;
        private static GenericRepository<WorkshopContent> _workshopContentRepository;
        private static WorkshopItemService _workshopItemService;
        private static WorkshopContentService _workshopContentService;

        private static GenericRepository<AboutPageContents> _aboutPageContentsRepository;
        private static AboutPageContentService _aboutPageContentService;

        private static GenericRepository<SolutionPageContent> _solutionPageContentsRepository;
        private static SolutionPageContentService _solutionPageContentService;

        private static GenericRepository<IndustryPageContent> _industryPageContentsRepository;
        private static IndustryPageContentService _industryPageContentService;

        private static GenericRepository<MottoItem> _mottoRepository;
        private static MottoService _mottoService;

        private static GenericRepository<ReportContent> _reportContentRepository;
        private static ReportContentService _reportContentService;
        private static GenericRepository<ReportItem> _reportItemRepository;
        private static ReportItemService _reportItemService;

        private static GenericRepository<VideoContents> _videoContentRepository;
        private static VideoContentService _videoContentService;

        private static GenericRepository<ContactInfo> _contactRepository;
        private static ContactInfoService _contactService;

        private static GenericRepository<CareerInfo> _careerRepository;
        private static CareerInfoService _careerService;


        public HomeController()
        {
            //string connectionString = @"Server=N04155-1013\OMERSRV;Database=CendDB;Trusted_Connection=True;";
            _context = new WebSiteContext(ConfigurationManager.ConnectionStrings["CendDBConnection"].ConnectionString);
            _unitOfWork = new UnitOfWork(_context);

            _newsItemRepository = new GenericRepository<NewsItem>(_context);
            _newsContentRepository = new GenericRepository<NewsContent>(_context);
            _expertInfoRepository = new GenericRepository<ExpertInfo>(_context);
            _workshopContentRepository = new GenericRepository<WorkshopContent>(_context);
            _workshopItemRepository = new GenericRepository<WorkshopItem>(_context);

            _newsItemService = new NewsItemService(_unitOfWork, _newsItemRepository);
            _newsContentService = new NewsContentService(_unitOfWork, _newsContentRepository);
            _expertService = new ExpertService(_unitOfWork, _expertInfoRepository);
            _workshopItemService = new WorkshopItemService(_unitOfWork, _workshopItemRepository);
            _workshopContentService = new WorkshopContentService(_unitOfWork, _workshopContentRepository);

            _aboutPageContentsRepository = new GenericRepository<AboutPageContents>(_context);
            _solutionPageContentsRepository = new GenericRepository<SolutionPageContent>(_context);
            _industryPageContentsRepository = new GenericRepository<IndustryPageContent>(_context);

            _aboutPageContentService = new AboutPageContentService(_unitOfWork, _aboutPageContentsRepository);
            _solutionPageContentService = new SolutionPageContentService(_unitOfWork, _solutionPageContentsRepository);
            _industryPageContentService = new IndustryPageContentService(_unitOfWork, _industryPageContentsRepository);

            _mottoRepository = new GenericRepository<MottoItem>(_context);
            _mottoService = new MottoService(_unitOfWork, _mottoRepository);

            _reportContentRepository = new GenericRepository<ReportContent>(_context);
            _reportItemRepository = new GenericRepository<ReportItem>(_context);
            _videoContentRepository = new GenericRepository<VideoContents>(_context);

            _reportContentService = new ReportContentService(_unitOfWork, _reportContentRepository);
            _reportItemService = new ReportItemService(_unitOfWork, _reportItemRepository);
            _videoContentService = new VideoContentService(_unitOfWork, _videoContentRepository);

            _sliderRepository = new GenericRepository<SliderContent>(_context);
            _sliderService = new SliderService(_unitOfWork, _sliderRepository);

            _contactRepository = new GenericRepository<ContactInfo>(_context);
            _contactService = new ContactInfoService(_unitOfWork, _contactRepository);

            _careerRepository = new GenericRepository<CareerInfo>(_context);
            _careerService = new CareerInfoService(_unitOfWork, _careerRepository);
        }

        public ActionResult Index()
        {
            if (Request.Cookies.AllKeys.Contains("_culture"))
            {
                Request.Cookies["_culture"].Value = "tr-TR";
            }
            AddCookie();
            //PageService objx = PageService.PageServiceInstance(connectionString);
            //objx.InitializeServices();

            //CategoryService categoryService = new CategoryService(connectionString);

            //PageItemService pageItemService = objx.GetItemService() as PageItemService;

            //return View(categoryService.GetAll());

            var sliderList = _sliderService.GetAllElements().First();

            ViewBag.About = CENDLocalization.IndexMotto1;
            ViewBag.KickStart = CENDLocalization.IndexMotto2;

            //ViewBag.MottoIndex = _mottoService.GetAllElements().FirstOrDefault().MainMotto;
            //ViewBag.MottoIndexTR = _mottoService.GetAllElements().FirstOrDefault().MainMottoTR;

            ViewBag.MottoIndexImage1 = sliderList.MottoImage1;
            ViewBag.MottoIndexImage1TR = sliderList.MottoImage1TR;

            ViewBag.MottoIndexImage2 = sliderList.MottoImage2;
            ViewBag.MottoIndexImage2TR = sliderList.MottoImage2TR;

            ViewBag.MottoIndexImage3 = sliderList.MottoImage3;
            ViewBag.MottoIndexImage3TR = sliderList.MottoImage3TR;

            ViewBag.MottoIndexImage4 = sliderList.MottoImage4;
            ViewBag.MottoIndexImage4TR = sliderList.MottoImage4TR;

            ViewBag.MottoIndexImage5 = sliderList.MottoImage5;
            ViewBag.MottoIndexImage5TR = sliderList.MottoImage5TR;

            return View(sliderList);
        }

        private void AddCookie()
        {
            if (!Request.Cookies.AllKeys.Contains("_culture"))
            {
                HttpCookie langCookie = new HttpCookie("_culture");
                langCookie.Value = "tr-TR";
                Request.Cookies.Add(langCookie);
            }
            else
            {
                Request.Cookies["_culture"].Value = "tr-TR";
            }
        }

        public ActionResult News(int page)
        {
            AddCookie();

            ViewBag.Entrance = CENDLocalization.NewsPageMotto;
            ViewBag.MottoNews = _mottoService.GetAllElements().FirstOrDefault().NewsMotto;
            ViewBag.MottoNewsTR = _mottoService.GetAllElements().FirstOrDefault().NewsMottoTR;

            var itemList = _newsItemService.GetAllElements().ToList();
            var contentList = _newsContentService.GetAllElements().Where(a => a.IsActive == true && a.IsDeleted == false).ToList();
            List<News> returnList = new List<News>();
            (from nI in itemList
             join nC in contentList on nI.Id equals nC.NewsItemId
             select new
             {
                 nI.Name,
                 nI.Id,
                 nI.NameTR,
                 nC.Text,
                 nC.TextTR,
                 nC.ImageUrl
             }).ToList().ForEach((t) =>
                             {
                                 News obj = new News();
                                 obj.Name = t.Name;
                                 obj.NameTR = t.NameTR;
                                 obj.Text = t.Text;
                                 obj.TextTR = t.TextTR;
                                 obj.ImageUrl = t.ImageUrl;
                                 obj.Id = t.Id;
                                 returnList.Add(obj);
                             });


            return View(returnList.ToPagedList(page, 4));

            //return View(returnList);
        }

        public ActionResult NewsDetail(int newsItemId)
        {
            AddCookie();
            ViewBag.Entrance = CENDLocalization.NewsPageMotto;
            ViewBag.Others = CENDLocalization.OtherNews;

            var item = _newsItemService.GetElementById(newsItemId);
            var content = _newsContentService.GetAllElements().Where(a => a.IsActive == true);

            var returnObj = (from cn in content
                             where cn.NewsItemId == newsItemId
                             select cn).FirstOrDefault();
            News obj = new News();
            obj.Id = newsItemId;
            obj.Name = item.Name;
            obj.NameTR = item.NameTR;
            obj.Text = returnObj.Text;
            obj.TextTR = returnObj.TextTR;
            obj.ImageUrl = returnObj.ImageUrl;

            return View(obj);
        }

        public ActionResult About()
        {
            AddCookie();
            ViewBag.Complete = CENDLocalization.AboutPageMotto;

            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;

            ViewBag.MottoAbout = _mottoService.GetAllElements().FirstOrDefault().AboutMotto;
            ViewBag.MottoAboutTR = _mottoService.GetAllElements().FirstOrDefault().AboutMottoTR;


            return View();
        }

        public ActionResult Contact()
        {
            AddCookie();
            ViewBag.ContactPageMotto = CENDLocalization.ContactPageMotto;
            ViewBag.ContactForm = CENDLocalization.ContactForm;
            ViewBag.ContactUs = CENDLocalization.ContactUs;

            ViewBag.CName = CENDLocalization.CName;
            ViewBag.Ccity = CENDLocalization.Ccity;
            ViewBag.Ccountry = CENDLocalization.Ccountry;
            ViewBag.Cemail = CENDLocalization.Cemail;
            ViewBag.Cmessage = CENDLocalization.Cmessage;
            ViewBag.Cphone = CENDLocalization.Cphone;
            ViewBag.CSurname = CENDLocalization.CSurname;

            ViewBag.MottoContact = _mottoService.GetAllElements().FirstOrDefault().ContactMotto;
            ViewBag.MottoContactTR = _mottoService.GetAllElements().FirstOrDefault().ContactMottoTR;

            return View();
        }

        [HttpPost]
        public ActionResult Contact(FormCollection collection)
        {
            AddCookie();
            ViewBag.ContactPageMotto = CENDLocalization.ContactPageMotto;
            ViewBag.ContactForm = CENDLocalization.ContactForm;
            ViewBag.ContactUs = CENDLocalization.ContactUs;

            ViewBag.CName = CENDLocalization.CName;
            ViewBag.Ccity = CENDLocalization.Ccity;
            ViewBag.Ccountry = CENDLocalization.Ccountry;
            ViewBag.Cemail = CENDLocalization.Cemail;
            ViewBag.Cmessage = CENDLocalization.Cmessage;
            ViewBag.Cphone = CENDLocalization.Cphone;
            ViewBag.CSurname = CENDLocalization.CSurname;

            ViewBag.MottoContact = _mottoService.GetAllElements().FirstOrDefault().ContactMotto;
            ViewBag.MottoContactTR = _mottoService.GetAllElements().FirstOrDefault().ContactMottoTR;

            try
            {
                if (ModelState.IsValid)
                {
                    ContactInfo data = new ContactInfo { Name = collection[0], Surname = collection[1], Email = collection[2], Telephone = collection[3], Message = collection[4] };
                    data.CreatedDate = DateTime.Today;
                    data.IsActive = true;
                    data.IsDeleted = false;
                    data.ModifiedDate = DateTime.Today;

                    _contactService.CreateElement(data);
                    _contactService.SaveChanges();

                    Response.Write("<script type='text/javascript'>confirm(\"İletiniz başarıyla gönderilmiştir.\");</script>");
                    return View();
                }
                else
                {
                    return View();
                }
            }
            catch (Exception)
            {

                return View();
            }
        }

        public ActionResult Projects(int page)
        {
            AddCookie();
            ViewBag.ProjectMotto = CENDLocalization.ProjectPageMotto;

            ViewBag.MottoProjects = _mottoService.GetAllElements().FirstOrDefault().TrainingMotto;
            ViewBag.MottoProjectsTR = _mottoService.GetAllElements().FirstOrDefault().TrainingMottoTR;

            var itemList = _workshopItemService.GetAllElements().ToList();
            var contentList = _workshopContentService.GetAllElements().Where(a => a.IsActive == true && a.IsDeleted == false).ToList();
            List<Workshops> returnList = new List<Workshops>();
            (from nI in itemList
             join nC in contentList on nI.Id equals nC.WorkshopItemId
             select new
             {
                 nI.Name,
                 nI.Id,
                 nI.NameTR,
                 nC.Text,
                 nC.TextTR,
                 nC.VideoUrl,
                 nC.ImageUrl
             }).ToList().ForEach((t) =>
             {
                 Workshops obj = new Workshops();
                 obj.Name = t.Name;
                 obj.NameTR = t.NameTR;
                 obj.Text = t.Text;
                 obj.TextTR = t.TextTR;
                 obj.Id = t.Id;
                 obj.VideoUrl = t.VideoUrl;
                 obj.ImageUrl = t.ImageUrl;
                 returnList.Add(obj);
             });

            return View(returnList.ToPagedList(page, 4));

            //return View(returnList);
        }

        public ActionResult ProjectDetail(int projectItemId)
        {
            AddCookie();
            var t = _workshopItemService.GetElementById(projectItemId);
            var content = _workshopContentService.GetAllElements().Where(a => a.IsActive == true);

            var returnObj = (from cn in content
                             where cn.WorkshopItemId == projectItemId
                             select cn).FirstOrDefault();

            Workshops obj = new Workshops();
            obj.Name = t.Name;
            obj.NameTR = t.NameTR;
            obj.Text = returnObj.Text;
            obj.TextTR = returnObj.TextTR;
            obj.Id = projectItemId;
            obj.VideoUrl = returnObj.VideoUrl;
            obj.ImageUrl = returnObj.ImageUrl;

            return View(obj);
        }

        public ActionResult Experts()
        {
            AddCookie();
            ViewBag.ExpertMotto = CENDLocalization.ExpertPageMotto;

            ViewBag.MottoExpert = _mottoService.GetAllElements().FirstOrDefault().ExpertMotto;
            ViewBag.MottoExpertTR = _mottoService.GetAllElements().FirstOrDefault().ExpertMottoTR;

            var itemList = _expertService.GetAllElements().Where(a => a.IsActive == true && a.IsDeleted == false).ToList();

            return View(itemList);
        }

        public ActionResult ExpertDetail(int expertId)
        {
            AddCookie();
            var obj = _expertService.GetElementById(expertId);
            return View(obj);
        }

        public ActionResult iThink()
        {
            AddCookie();
            return View();
        }

        public ActionResult iThinkDetail()
        {
            return View();
        }

        public ActionResult Reports(int page)
        {
            AddCookie();
            ViewBag.ReportMotto = CENDLocalization.ReportPageMotto;

            ViewBag.MottoReports = _mottoService.GetAllElements().FirstOrDefault().ReportMotto;
            ViewBag.MottoReportsTR = _mottoService.GetAllElements().FirstOrDefault().ReportMottoTR;

            var itemList = _reportItemService.GetAllElements().ToList();
            var contentList = _reportContentService.GetAllElements().Where(a => a.IsActive == true && a.IsDeleted == false).ToList();
            List<Reports> returnList = new List<Reports>();
            (from nI in itemList
             join nC in contentList on nI.Id equals nC.ReportItemId
             select new
             {
                 nI.Name,
                 nI.Id,
                 nI.NameTR,
                 nC.ShortDescription,
                 nC.ShortDescriptionTR,
                 nC.VideoUrl,
                 nC.ReportUrl
             }).ToList().ForEach((t) =>
             {
                 Reports obj = new Reports();
                 obj.Name = t.Name;
                 obj.NameTR = t.NameTR;
                 obj.ShortDescription = t.ShortDescription;
                 obj.ShortDescriptionTR = t.ShortDescriptionTR;
                 obj.Id = t.Id;
                 obj.VideoUrl = t.VideoUrl;
                 obj.ReportURL = t.ReportUrl;
                 returnList.Add(obj);
             });

            return View(returnList.ToPagedList(page, 4));
        }

        public ActionResult ReportDetail(int reportId)
        {
            AddCookie();
            var item = _reportItemService.GetElementById(reportId);
            var content = _reportContentService.GetAllElements().Where(a => a.IsActive == true);

            var returnObj = (from cn in content
                             where cn.ReportItemId == reportId
                             select cn).FirstOrDefault();
            Reports obj = new Reports();
            obj.Id = reportId;
            obj.Name = item.Name;
            obj.NameTR = item.NameTR;
            obj.ShortDescription = returnObj.ShortDescription;
            obj.ShortDescriptionTR = returnObj.ShortDescriptionTR;
            obj.ReportURL = returnObj.ReportUrl;

            return View(obj);
        }

        public FileResult ReportDownload(int reportId)
        {
            var item = _reportItemService.GetElementById(reportId);
            var content = _reportContentService.GetAllElements().Where(a => a.IsActive == true);

            var returnObj = (from cn in content
                             where cn.ReportItemId == reportId
                             select cn).FirstOrDefault();
            Reports obj = new Reports();
            obj.Id = reportId;
            obj.Name = item.Name;
            obj.NameTR = item.NameTR;
            obj.ShortDescription = returnObj.ShortDescription;
            obj.ShortDescriptionTR = returnObj.ShortDescriptionTR;
            obj.ReportURL = returnObj.ReportUrl;

            string contentType = "application/pdf";

            return File(Server.MapPath("~/Content/Files/") + obj.ReportURL, contentType, "Report-" + obj.Name + ".pdf");

            //return View(obj);
        }

        public ActionResult Videos(int page)
        {
            AddCookie();
            ViewBag.VideoMotto = CENDLocalization.VideoPageMotto;

            ViewBag.MottoVideo = _mottoService.GetAllElements().FirstOrDefault().VideoMotto;
            ViewBag.MottoVideoTR = _mottoService.GetAllElements().FirstOrDefault().VideoMottoTR;

            var itemList = _videoContentService.GetAllElements().Where(a => a.IsActive == true).ToList();

            return View(itemList.ToPagedList(page, 4));
        }

        public ActionResult VideoDetail(int videoId)
        {
            AddCookie();
            var t = _videoContentService.GetElementById(videoId);
            //var content = _videoContentService.GetAllElements().Where(a => a.IsActive == true);

            //var returnObj = (from cn in content
            //where cn.Id == videoId
            //select cn).FirstOrDefault();

            return View(t);
        }

        public ActionResult Blog()
        {
            AddCookie();
            return View();
        }


        #region About Pages

        public ActionResult WhyCend()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _aboutPageContentService.GetAllElements().First();
            return View(obj);
        }

        public ActionResult IndustryExpertise()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _industryPageContentService.GetAllElements().First();
            return View(obj);
        }

        public ActionResult Solutions()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _solutionPageContentService.GetAllElements().First();
            return View(obj);
        }

        public ActionResult Mission()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _aboutPageContentService.GetAllElements().First();
            return View(obj);
        }

        public ActionResult Management()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _aboutPageContentService.GetAllElements().First();
            return View(obj);
        }

        public ActionResult Career()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _aboutPageContentService.GetAllElements().First();
            return View(obj);
        }

        [HttpPost]
        public ActionResult Career(FormCollection collection)
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;

            try
            {
                if (ModelState.IsValid)
                {
                    CareerInfo data = new CareerInfo { Name = collection[0], Surname = collection[1], Email = collection[2], Telephone = collection[3], Message = collection[4] };
                    data.CreatedDate = DateTime.Today;
                    data.IsActive = true;
                    data.IsDeleted = false;
                    data.ModifiedDate = DateTime.Today;

                    _careerService.CreateElement(data);
                    _careerService.SaveChanges();
                    Response.Write("<script type='text/javascript'>confirm(\"İletiniz başarıyla gönderilmiştir.\");</script>");
                    return View();
                }
                else
                {
                    return View();
                }
            }
            catch (Exception)
            {

                return View();
            }
        }

        public ActionResult Terms()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _aboutPageContentService.GetAllElements().First();
            return View(obj);
        }

        public ActionResult HealthCare()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _industryPageContentService.GetAllElements().First();
            return View(obj);
        }

        public ActionResult Biotech()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _industryPageContentService.GetAllElements().First();
            return View(obj);
        }

        public ActionResult Medical()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _industryPageContentService.GetAllElements().First();
            return View(obj);
        }

        public ActionResult Consulting()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _solutionPageContentService.GetAllElements().First();
            return View(obj);
        }

        public ActionResult ManagementConsulting()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _solutionPageContentService.GetAllElements().First();
            return View(obj);
        }

        public ActionResult ManagementMarketing()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _solutionPageContentService.GetAllElements().First();
            return View(obj);
        }

        public ActionResult Marketing()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _solutionPageContentService.GetAllElements().First();
            return View(obj);
        }

        public ActionResult Sales()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _solutionPageContentService.GetAllElements().First();
            return View(obj);
        }

        public ActionResult Support()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _solutionPageContentService.GetAllElements().First();
            return View(obj);
        }

        public ActionResult Outsource()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _solutionPageContentService.GetAllElements().First();
            return View(obj);
        }

        public ActionResult Training()
        {
            AddCookie();
            ViewBag.WhyCend = CENDLocalization.WhyCend;
            ViewBag.IndustryExpertise = CENDLocalization.IndustryExpertise;
            ViewBag.Solutions = CENDLocalization.Solutions;
            ViewBag.MissionAndValues = CENDLocalization.MissionAndValues;
            ViewBag.ManagementTeam = CENDLocalization.ManagementTeam;
            ViewBag.ManagementConsulting = CENDLocalization.ManagementConsulting;
            ViewBag.Career = CENDLocalization.Career;
            ViewBag.ContactUs = CENDLocalization.ContactUs;
            ViewBag.Terms = CENDLocalization.Terms;
            ViewBag.Biotech = CENDLocalization.Biotech;
            ViewBag.HealthCare = CENDLocalization.HealthCare;
            ViewBag.Medical = CENDLocalization.Medical;
            ViewBag.Consulting = CENDLocalization.Consulting;
            ViewBag.StrategicMarketing = CENDLocalization.StrategicMarketing;
            ViewBag.Sales = CENDLocalization.Sales;
            ViewBag.SupportService = CENDLocalization.SupportService;
            ViewBag.Outsource = CENDLocalization.Outsource;
            ViewBag.Training = CENDLocalization.Training;
            var obj = _solutionPageContentService.GetAllElements().First();
            return View(obj);
        }

        #endregion

        public static IList<News> GetNewsItems()
        {
            var itemList = _newsItemService.GetAllElements().ToList();
            var contentList = _newsContentService.GetAllElements().Where(a => a.IsActive == true && a.IsDeleted == false).ToList();
            List<News> returnList = new List<News>();
            (from nI in itemList
             join nC in contentList on nI.Id equals nC.NewsItemId
             select new
             {
                 nI.Name,
                 nI.Id,
                 nI.NameTR,
                 nC.Text,
                 nC.TextTR
             }).ToList().ForEach((t) =>
             {
                 News obj = new News();
                 obj.Name = t.Name;
                 obj.NameTR = t.NameTR;
                 obj.Text = t.Text;
                 obj.TextTR = t.TextTR;
                 obj.Id = t.Id;
                 returnList.Add(obj);
             });

            return returnList;
        }

        public static IList<ExpertInfo> GetExpertItems()
        {
            var itemList = _expertService.GetAllElements().Where(a => a.IsActive == true && a.IsDeleted == false).ToList();

            return itemList;
        }

        public static IList<Workshops> GetWorkshopItems()
        {
            var itemList = _workshopItemService.GetAllElements().ToList();
            var contentList = _workshopContentService.GetAllElements().Where(a => a.IsActive == true && a.IsDeleted == false).ToList();
            List<Workshops> returnList = new List<Workshops>();
            (from nI in itemList
             join nC in contentList on nI.Id equals nC.WorkshopItemId
             select new
             {
                 nI.Name,
                 nI.Id,
                 nI.NameTR,
                 nC.Text,
                 nC.TextTR,
                 nC.VideoUrl,
                 nC.ImageUrl
             }).ToList().ForEach((t) =>
             {
                 Workshops obj = new Workshops();
                 obj.Name = t.Name;
                 obj.NameTR = t.NameTR;
                 obj.Text = t.Text;
                 obj.TextTR = t.TextTR;
                 obj.Id = t.Id;
                 obj.VideoUrl = t.VideoUrl;
                 obj.ImageUrl = t.ImageUrl;
                 returnList.Add(obj);
             });
            return returnList;
        }
    }
}
